//
//  ProductTableViewCell.m
//  片刻
//
//  Created by lanou3g on 15/6/4.
//  Copyright (c) 2015年 lanou3g. All rights reserved.
//

#import "ProductTableViewCell.h"
#import "MaocHeader.h"
#import <UIImageView+WebCache.h> //第三方类库

@implementation ProductTableViewCell

- (void)awakeFromNib {
    // Initialization code
}
-(void)dealloc{
    [_mainImageView release];
    [_titleLabel release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 165, 200, 30)];
        _mainImageView = [[UIImageView alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-304)/2, 10, 304, 150)];
        _buyButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
        _buyButton.frame = CGRectMake(250, 170, 60, 20);
        [_buyButton setTitle:@"立即购买" forState:(UIControlStateNormal)];
        [_buyButton addTarget:self action:@selector(handleButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
        _buyButton.backgroundColor = [UIColor orangeColor];
        _mainImageView.backgroundColor = [UIColor orangeColor];
        
        [self.contentView addSubview:_titleLabel];
        [self.contentView addSubview:_buyButton];
        [self.contentView addSubview:_mainImageView];
        
        [_titleLabel release];
        [_mainImageView release];
        
    }
    return self;
}

-(void)handleButtonAction:(UIButton *)button{
//    实现浏览器的跳转
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:_model.buyurl]];
}

-(void)setModel:(ProductModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
 
    }
    self.titleLabel.text = model.title;
    //第三方类库方法 加载图片
    [self.mainImageView sd_setImageWithURL:[NSURL URLWithString:model.coverimg]];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
